package org.nabc.configuration;

import com.mysql.cj.jdbc.ConnectionImpl;
import com.mysql.cj.jdbc.Driver;
import lombok.Builder;
import lombok.Data;
import lombok.SneakyThrows;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

@Data
@Builder
public class DataSource {
    private String url;
    private String driverName;
    private String username;
    private String password;
    private static Connection connection;

    @SneakyThrows
    public Connection getConnection() {
        if (connection != null) {
            return connection;
        }

        Class.forName(driverName);
        connection = DriverManager.getConnection(url, username, password);
        return connection;
    }
}
